home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / scripts / neon-logo.scm.z / neon-logo.scm
Encoding:
GIMP Script-Fu Script  |  1999-07-21  |  5.2 KB  |  167 lines

  1. ;  NEON
  2. ;  Create a text effect that simulates neon lighting
  3.  
  4. (define (set-pt a index x y)
  5.   (prog1
  6.    (aset a (* index 2) x)
  7.    (aset a (+ (* index 2) 1) y)))
  8.  
  9. (define (neon-spline1)
  10.   (let* ((a (cons-array 6 'byte)))
  11.     (set-pt a 0 0 0)
  12.     (set-pt a 1 127 145)
  13.     (set-pt a 2 255 255)
  14.     a))
  15.  
  16. (define (neon-spline2)
  17.   (let* ((a (cons-array 6 'byte)))
  18.     (set-pt a 0 0 0)
  19.     (set-pt a 1 110 150)
  20.     (set-pt a 2 255 255)
  21.     a))
  22.  
  23. (define (neon-spline3)
  24.   (let* ((a (cons-array 6 'byte)))
  25.     (set-pt a 0 0 0)
  26.     (set-pt a 1 100 185)
  27.     (set-pt a 2 255 255)
  28.     a))
  29.  
  30. (define (find-hue-offset color)
  31.   (let* ((R (car color))
  32.      (G (cadr color))
  33.      (B (caddr color))
  34.      (max-val (max R G B))
  35.      (min-val (min R G B))
  36.      (delta (- max-val min-val))
  37.      (hue 0))
  38.     (if (= max 0) 0
  39.     (begin
  40.       (cond ((= max-val R) (set! hue (/ (- G B) (* 1.0 delta))))
  41.         ((= max-val G) (set! hue (+ 2 (/ (- B R) (* 1.0 delta)))))
  42.         ((= max-val B) (set! hue (+ 4 (/ (- R G) (* 1.0 delta))))))
  43.       (set! hue (* hue 60))
  44.       (if (< hue 0) (set! hue (+ hue 360)))
  45.       (if (> hue 360) (set! hue (- hue 360)))
  46.       (if (> hue 180) (set! hue (- hue 360)))
  47.       hue))))
  48.  
  49. (define (script-fu-neon-logo text size font bg-color glow-color shadow)
  50.   (let* ((img (car (gimp-image-new 256 256 RGB)))
  51.      (tube-hue (find-hue-offset glow-color))
  52.      (border (/ size 4))
  53.      (shrink (/ size 14))
  54.      (grow (/ size 40))
  55.      (feather (/ size 5))
  56.      (feather1 (/ size 25))
  57.      (feather2 (/ size 12))
  58.      (inc-shrink (/ size 100))
  59.      (shadow-shrink (/ size 40))
  60.      (shadow-feather (/ size 20))
  61.      (shadow-offx (/ size 10))
  62.      (shadow-offy (/ size 10))
  63.      (tube-layer (car (gimp-text img -1 0 0 text border TRUE size PIXELS "*" font "*" "*" "*" "*")))
  64.      (width (car (gimp-drawable-width tube-layer)))
  65.      (height (car (gimp-drawable-height tube-layer)))
  66.      (glow-layer (car (gimp-layer-new img width height RGBA_IMAGE "Neon Glow" 100 NORMAL)))
  67.      (bg-layer (car (gimp-layer-new img width height RGB_IMAGE "Background" 100 NORMAL)))
  68.      (shadow-layer (if (= shadow TRUE)
  69.                (car (gimp-layer-new img width height RGBA_IMAGE "Shadow" 100 NORMAL))
  70.                0))
  71.      (selection 0)
  72.      (old-fg (car (gimp-palette-get-foreground)))
  73.      (old-bg (car (gimp-palette-get-background))))
  74.     (gimp-image-disable-undo img)
  75.     (gimp-image-resize img width height 0 0)
  76.     (gimp-image-add-layer img bg-layer 1)
  77.     (if (not (= shadow 0))
  78.     (begin
  79.       (gimp-image-add-layer img shadow-layer 1)
  80.       (gimp-edit-clear img shadow-layer)))
  81.     (gimp-image-add-layer img glow-layer 1)
  82.  
  83.     (gimp-palette-set-background '(0 0 0))
  84.     (gimp-selection-layer-alpha img tube-layer)
  85.     (set! selection (car (gimp-selection-save img)))
  86.     (gimp-selection-none img)
  87.  
  88.     (gimp-edit-clear img glow-layer)
  89.     (gimp-edit-fill img tube-layer)
  90.  
  91.     (gimp-palette-set-background bg-color)
  92.     (gimp-edit-fill img bg-layer)
  93.  
  94.     (gimp-selection-load img selection)
  95.     (gimp-palette-set-background '(255 255 255))
  96.     (gimp-edit-fill img tube-layer)
  97.     (gimp-selection-shrink img shrink)
  98.     (gimp-palette-set-background '(0 0 0))
  99.     (gimp-edit-fill img selection)
  100.     (gimp-edit-fill img tube-layer)
  101.  
  102.     (gimp-selection-none img)
  103.     (if (not (= feather1 0)) (plug-in-gauss-rle 1 img tube-layer feather1 TRUE TRUE))
  104.     (gimp-selection-load img selection)
  105.     (if (not (= feather2 0)) (plug-in-gauss-rle 1 img tube-layer feather2 TRUE TRUE))
  106.  
  107.     (gimp-brightness-contrast img tube-layer -10 15)
  108.     (gimp-selection-none img)
  109.     (gimp-hue-saturation img tube-layer 0 tube-hue -15 70)
  110.  
  111.     (gimp-selection-load img selection)
  112.     (gimp-selection-feather img inc-shrink)
  113.     (gimp-selection-shrink img inc-shrink)
  114.     (gimp-curves-spline img tube-layer 0 6 (neon-spline1))
  115.  
  116.     (gimp-selection-load img selection)
  117.     (gimp-selection-feather img inc-shrink)
  118.     (gimp-selection-shrink img (* inc-shrink 2))
  119.     (gimp-curves-spline img tube-layer 0 6 (neon-spline2))
  120.  
  121.     (gimp-selection-load img selection)
  122.     (gimp-selection-feather img inc-shrink)
  123.     (gimp-selection-shrink img (* inc-shrink 3))
  124.     (gimp-curves-spline img tube-layer 0 6 (neon-spline3))
  125.  
  126.     (gimp-selection-load img selection)
  127.     (gimp-selection-grow img grow)
  128.     (gimp-selection-invert img)
  129.     (gimp-edit-clear img tube-layer)
  130.     (gimp-selection-invert img)
  131.  
  132.     (gimp-selection-feather img feather)
  133.     (gimp-palette-set-background glow-color)
  134.     (gimp-edit-fill img glow-layer)
  135.  
  136.     (if (not (= shadow 0))
  137.     (begin
  138.       (gimp-selection-layer-alpha img tube-layer)
  139.       (gimp-selection-shrink img shadow-shrink)
  140.       (gimp-selection-feather img shadow-feather)
  141.       (gimp-selection-translate img shadow-offx shadow-offy)
  142.       (gimp-palette-set-background '(0 0 0))
  143.       (gimp-edit-fill img shadow-layer)))
  144.     (gimp-selection-none img)
  145.  
  146.     (gimp-layer-set-name tube-layer "Neon Tubes")
  147.     (gimp-palette-set-background old-bg)
  148.     (gimp-palette-set-foreground old-fg)
  149.     (gimp-image-remove-channel img selection)
  150.     (gimp-image-enable-undo img)
  151.     (gimp-display-new img)))
  152.  
  153.  
  154. (script-fu-register "script-fu-neon-logo"
  155.             "<Toolbox>/Xtns/Script-Fu/Logos/Neon"
  156.             "Neon logos"
  157.             "Spencer Kimball"
  158.             "Spencer Kimball"
  159.             "1997"
  160.             ""
  161.             SF-VALUE "Text String" "\"NEON\""
  162.             SF-VALUE "Font Size (in pixels)" "150"
  163.             SF-VALUE "Font" "\"Blippo\""
  164.             SF-COLOR "Background Color" '(0 0 0)
  165.             SF-COLOR "Glow Color" '(38 211 255)
  166.             SF-TOGGLE "Create Shadow" FALSE)
  167.